<template>
  <div class="silide-pic">
    <div class="carousel-wrap" id="carousel">
      <!-- 轮播图列表 -->
      <transition-group tag="ul" class='slide-ul' name="list">
        <li v-for="(list,index) in slideList" :key="'slide'+index" v-show="index===currentIndex" @mouseenter="stopPlay" @mouseleave="playSlide">
          <a :href="list.clickUrl" >
            <img :src="list.imgUrl" :alt="list.desc">
            <!-- <div class="desc">{{list.desc}}</div> -->
          </a>
        </li>
      </transition-group>
      <!-- 轮播图位置指示 -->
      <!-- <div class="carousel-items">
        <span v-for="(item,index) in slideList.length"
              :key="index"
              :class="{'active':index===currentIndex}"
              @mouseover="change(index)"></span>
      </div> -->
      <div v-if="slideList.length != 0" class="prev-btn btn" @click="goPrevPage">
        <span class="icon-zuojiantou"></span>
      </div>
      <div v-if="slideList.length != 0" class="next-btn btn" @click="goNextPage">
        <span class="icon-youjiantou"></span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      slideList: [
        {
          clickUrl: "#",
          desc: "教育部产学合作协同育人项目申报平台1",
          imgUrl: "/img/talents/home/banner1.png"
        },
        {
          clickUrl: "#",
          desc: "教育部产学合作协同育人项目申报平台2",
          imgUrl: "/img/talents/home/banner2.png"
        },
        {
          clickUrl: "#",
          desc: "教育部产学合作协同育人项目申报平台3",
          imgUrl: "/img/talents/home/banner3.png"
        }
      ],
      currentIndex: 0,
      timer: ''
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.timer = setInterval(() => {
        this.autoPlay()
      }, 6000)
    })
  },
  methods: {
    playSlide() {
      this.timer = setInterval(() => {
          this.autoPlay()
      }, 6000)
    },
    stopPlay () {
      clearInterval(this.timer)
      this.timer = null
    },
    // change (index) {
    //   this.currentIndex = index
    // },
    autoPlay() {
      this.currentIndex++
      if (this.currentIndex > this.slideList.length - 1) {
          this.currentIndex = 0
      }
    },
    // 上一页
    goPrevPage () {
      if(this.currentIndex == 0) {
        this.currentIndex = this.slideList.length - 1;
      } else {
        this.currentIndex = this.currentIndex - 1;
      }
    },
    // 下一页
    goNextPage () {
      if(this.currentIndex == this.slideList.length - 1) {
        this.currentIndex = 0
      } else {
        this.currentIndex = this.currentIndex + 1;
      }
    }
  }
}
</script>
<style lang="stylus" scoped>
  .silide-pic {
    .carousel-wrap {
      position: relative;
      width: 680px;
      height: 413px;
      overflow: hidden;
      // 删除
      background-color: #fff;
      .slide-ul {
        width: 100%;
        height: 100%;
        li {
          position: absolute;
          width: 100%;
          height: 100%;
          img {
            width: 100%;
            height: 100%;
          }
          .desc {
            position: absolute;
            font-size: 18px;
            font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
            font-weight: bold;
            color: #FFFFFF;
            bottom: 27px;
            left: 20px
            &:hover {
              color: #1457FD
            }
          }
        }
      }
      .carousel-items {
        position: absolute;
        z-index: 10;
        bottom: 20px;
        width: 100%;
        margin: 0 auto;
        text-align: right;
        font-size: 0;
        padding-right: 12px
        span {
          display: inline-block;
          height: 8px;
          width: 8px;
          margin: 0 10px;
          background: rgba(255, 255, 255, 0.3);
          cursor: pointer;
          border-radius: 50%
        }
        .active {
          background: #1457FD;
        }
      }
      .btn{
        position: absolute;
        width: 44px;
        height: 44px;
        border: 2px solid #fff;
        background-color: rgba(0, 0, 0, 0.3);
        text-align: center;
        line-height: 44px;
        cursor: pointer;
        transition: all 0.25s;
        top: 185px;
        &:hover{
          background-color: #1457FD;
          border: 2px solid transparent;
        }
      }
      .prev-btn {
        left: 30px;
      }
      .next-btn {
        right: 30px;
      }
    }
}
</style>